<template>
	<div>
		<el-button type="text" @click="dialogVisible = true">添加员工</el-button>
		<!-- :visible.sync="$store.state.bbsInfoflag" -->
		<el-dialog :close-on-click-modal="flag" :show-close="flag" title="员工信息" :visible.sync="dialogVisible"
		 width="30%" center>
			<span>
				<!-- ////////////////////// -->
				<el-form ref="form" label-width="80px">
					<el-form-item label="员工姓名">
						<el-input v-model="empInfo.empname" maxlength=15></el-input>
					</el-form-item>
					<el-form-item label="员工状态">
						<el-radio v-model="empInfo.empstate" :label="lab0">休假</el-radio>
						<el-radio v-model="empInfo.empstate" :label="lab1">忙碌</el-radio>
						<el-radio v-model="empInfo.empstate" :label="lab2">就绪</el-radio>
					</el-form-item>

					<el-form-item label="员工身份">
						<el-select v-model="empInfo.emptype" placeholder="请选择">
							<el-option :label="item" v-for="(item,i) in emptype" :key="i" :value="item"></el-option>
						</el-select>
					</el-form-item>
				</el-form>
				<!-- ////////////////////// -->
			</span>
			<span slot="footer" class="dialog-footer">
				<el-button @click="cancel()">取 消</el-button>
				<el-button type="primary" @click="Staffflag(false)">保存</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import {
		request
	} from "network/request.js"
	export default {
		data() {
			return {
				dialogVisible :false,
				empInfo: {
					"empid": 0,
					"empname": "员工姓名",
					"empremark": "string",
					"empstate": "1",
					"emptype": "长期服务",
				},
				lab0: '0',
				lab1: '1',
				lab2: '2',
				flag: false,
				flag2: true,
				bbstate2: "1",
				emptype: ""
			};
		},
		methods: {
			Staffflag(flag) {
				request({
					url: '/Meal/majorMeals',
					method: 'get',
				}).then(res => {
					if (this.empInfo.emptype == "长期服务") {
						this.empInfo.emptype = "A"
					} else if (this.empInfo.emptype == "短期服务") {
						this.empInfo.emptype = "B"
					} else {
						res.data.forEach(s => {
							if (s.majormealremark == this.empInfo.emptype) {
								this.empInfo.emptype = s.majormealid
							}
						})
					}

					request({
						url: '/Emp/empInfo',
						method: 'post',
						params: {
							// id:this.$store.state.mealid
							"empid": this.empInfo.empid,
							"empname": this.empInfo.empname,
							"empremark": this.empInfo.empremark,
							"empstate": this.empInfo.empstate,
							"emptype": this.empInfo.emptype
						}
					}).then(res => {
						this.dialogVisible=false 
						this.$router.push("blank_emt")
					})
				})

			},
			cancel() {
				this.dialogVisible=false 
				// this.$store.commit("updateMealid", 0)
			},
			onSubmit() {
				console.log('submit!');
			}
		},
		created() {
			let emptypes = ["长期服务", "短期服务"];
			request({
				url: '/Meal/majorMeals',
				method: 'get',
			}).then(res1 => {
				res1.data.forEach(s => {
					emptypes.push(s.majormealremark)
				})
				this.emptype = emptypes
			})

		}
	};
</script>

<style scoped>
	.el-select {
		width: 130px;
	}

	.input-with-select .el-input-group__prepend {
		background-color: #fff;
	}
</style>
